<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
	</head>
	<body>
	  <form>
	    用户名:<input type="text" name="username" id="username"><br />
	    密码：<input type="text" name="password" id="password"><br />
	    <input type="button" value="提交" id="btn"/>
	  </form>
	  <script>
	     let btnDom = document.getElementById("btn");
	     console.log(window)
	     btnDom.onclick=function(){
	       let formData = new FormData(document.querySelector("form"));
	       let xhr =  new XMLHttpRequest();
	       let search = [];
	       formData.forEach((val,key)=>{
	         search.push(`${encodeURIComponent(key)}=${encodeURIComponent(val)}`);
	       })
	       xhr.open("POST","http://localhost:8080/login",true);
	       xhr.send(formData);
	       xhr.onreadystatechange=function(e){
	         if(xhr.readyState == 4){
	           if(xhr.status>=200&&xhr.status<=300 || xhr.status==304){
	             alert("成功")
	           }else{
	             alert("失败")
	           }
	           
	         }
	       }
	       
	       
	     }
	     
	  </script>
	</body>
</html>
